import cgi
import os
from google.appengine.ext.webapp import template
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
from google.appengine.api import mail

from Model.entities import *

class MakeReservationForm(webapp.RequestHandler):
  def get(self):
    path = os.path.join(os.path.dirname(__file__), 'prazoEsgotado.html')
    self.response.out.write(template.render(path,{}))

class MakeReservationLogic(webapp.RequestHandler):
  def post(self):
    path = os.path.join(os.path.dirname(__file__), 'prazoEsgotado.html')
    self.response.out.write(template.render(path,{}))
    

class ListRoomLogic(webapp.RequestHandler):

  def get(self):
    rooms = Room.all().filter('sex !=', 'Any')
    rooms.order("number")
    template_values = {'rooms': rooms}
    path = os.path.join(os.path.dirname(__file__), 'listRooms.html')
    self.response.out.write(template.render(path, template_values))

class ListPeopleLogic(webapp.RequestHandler):

  def get(self):
    people = Person.all().order("name")
    template_values = {'people': people}
    path = os.path.join(os.path.dirname(__file__), 'listPeople.html')
    self.response.out.write(template.render(path, template_values))


class ViewReservationLogic(webapp.RequestHandler):

  def get(self):
    room = Room.get(self.request.get("room.key"))
    template_values = {'room': room}
    path = os.path.join(os.path.dirname(__file__), 'room.reservations.html')
    self.response.out.write(template.render(path, template_values))

class ListReservationsLogic(webapp.RequestHandler):

  def get(self):
    self.redirect("http://docs.google.com/View?docID=dd9nrtnt_89mqf8zd8&revision=_latest")

class MainPage(webapp.RequestHandler):

  def get(self):
    people = Person.all()
    people.order("name")
    template_values = {'people': people}
    path = os.path.join(os.path.dirname(__file__), 'index.html')
    self.response.out.write(template.render(path, template_values))

application = webapp.WSGIApplication(
                                     [('/', MainPage),
									  ('/viewReservations', ViewReservationLogic),
									  ('/makeReservation', MakeReservationLogic),
									  ('/makeReservationForm', MakeReservationForm),
                                      ('/listPeople', ListPeopleLogic),
								      ('/listRooms', ListRoomLogic),
									  ('/listReservations', ListReservationsLogic),
                                    ],
                                     debug=True)

def main():
  run_wsgi_app(application)

if __name__ == "__main__":
  main()